package com.briup.mt.service.impl;

import com.briup.mt.bean.*;
import com.briup.mt.dao.DatasetFileMapper;
import com.briup.mt.service.DatasetFileService;
import org.apache.catalina.LifecycleState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DatasetFileServiceimpl implements DatasetFileService {
    @Resource
    private DatasetFileMapper datasetFileMapper;

    @Override
    public List<DatasetFile> query(String name,Long datasetId) {
        DatasetFileExample example = new DatasetFileExample();
        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andFileRealNameLike("%"+name+"%");
        }
        if(datasetId != null){
            example.createCriteria().andDatasetIdEqualTo(datasetId);
        }
        return datasetFileMapper.selectByExample(example);
    }


    @Override
    public void saveOrUpdate(DatasetFile datasetFile) {
        if(datasetFile.getId() == null){
            datasetFileMapper.insert(datasetFile);
        } else {

            datasetFileMapper.updateByPrimaryKey(datasetFile);
        }
    }

    @Override
    public void deleteById(long id) {
        datasetFileMapper.deleteByPrimaryKey(id);
    }
}
